<template>
	<xbd-pages-content title="定期体检设置">
		<template #content>
			<view class="date-choose" :style="'minHeight:'+windowHeight+'px'">
				<view class="box" @click=" clickChack('never')">
					<text>不开启</text>
					<image v-if="check==='never'" class="image" src="../../static/images/health/check.svg" mode=""></image>
				</view>
				<view class="box"  @click="clickChack('month')">
					<text>每一个月体检一次</text>
					<image v-if="check==='month'" class="image" src="../../static/images/health/check.svg" mode=""></image>
				</view>
				<view class="box"  @click="clickChack('halfyear')">
					<text>每半年体检一次</text>
					<image  v-if="check==='halfyear'" class="image" src="../../static/images/health/check.svg" mode=""></image>
				</view>
				<view class="box"  @click="clickChack('year')">
					<text>每一年体检一次</text>
					<image v-if="check==='year'" class="image" src="../../static/images/health/check.svg" mode=""></image>
				</view>
				<button class="button" @click="save">保存设置</button>
			</view>
		</template>
	</xbd-pages-content>
</template>

<script>
	import { Health } from '@/api/index.js';
	export default {
			data(){
				return{
					check:'',
					windowHeight:0,
				}
			},
			methods:{
				clickChack(val){
					this.check = val
				},
				async init(){
					try {
					    const res = await Health.getFrequency()
						this.check = res.data.type

					} catch (e) {
					    // error
					}
				},
				async save(){
					const o = {
							type: this.check || 'never'
						}
					try {
						
					    const res = await Health.postFrequency(o)
						console.log(res)
						// uni.$emit('periodic',this.check);
						setTimeout(() => {
							uni.navigateBack({
							    delta:1
							});
						}, 1000);
					} catch (e) {
						this.$showToast('保存失败,请重新尝试');
					    // error
					}
				},
			},
			async onLoad(){
				await this.init(),
				 uni.getSystemInfo({
				     success:(res) =>{
						 this.windowHeight = res.windowHeight
				     }
				 });
			}
				

	}
</script>

<style lang="scss" scoped>
.date-choose{
	box-sizing: border-box;
	padding: 0 40rpx;
	background-color: #FFFFFF;
	.box{
		display: flex;
		justify-content: space-between;
		padding: 13px 0 ;
		font-size: 28rpx;
		color: #666666 ;
		border-bottom: 1px solid #F8F8F8 ;
		.image{
			width: 32rpx;
			height: 32rpx;
		}
	}
	
	.button{
		box-sizing: border-box;
		margin: 0 auto;
		margin-top:150px;
		font-size: 28rpx;
		width: 300rpx;
		height: 32px;
		border-radius: 8rpx;
		line-height: 32px;
		background: url(../../static/images/common/bluebg.png) no-repeat;
		background-size: 100% 100%;
		color: $uni-text-color-inverse;
	}
	
}
</style>
